package com.zhongkun.datahome.service.res.setting;

import com.zhongkun.datahome.common.utils.bean.BeanUtils;
import com.zhongkun.datahome.service.domain.MiniProgramDataSetting;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Comparator;
import java.util.List;

/**
 * @Author: lifengsheng
 * @Date: 2025/5/8 14:25
 * @Desc
 */
@Data
public class AppDataSettingVo {
    private Long id;

    @ApiModelProperty("图标路径")
    private String iconUrl;

    @ApiModelProperty("类型名称")
    private String name;

    @ApiModelProperty("上级类目")
    private Long parentId;

    @ApiModelProperty("层级，0:末级类目 1：非末级类目")
    private Integer level;

    @ApiModelProperty("排序")
    private Integer sort;

    /**
     * @see  com.zhongkun.datahome.common.enums.DataSettingLinkTypeEnum
     */
    @ApiModelProperty("sign_file：签字材料，material_list：材料清单，other：其他自定义")
    private String linkType;

    @ApiModelProperty("子目录")
    private List<AppDataSettingVo> children;

    public static AppDataSettingVo of(MiniProgramDataSetting miniProgramDataSetting) {
        AppDataSettingVo appDataSettingVo = new AppDataSettingVo();
        BeanUtils.copyBeanProp(appDataSettingVo, miniProgramDataSetting);

        return appDataSettingVo;
    }

    public void setAndSortChildren(List<AppDataSettingVo> children) {
        if (CollectionUtils.isNotEmpty(children)) {
            children.sort(Comparator.comparingInt(AppDataSettingVo::getSort));
        }
        this.children = children;
    }
}
